﻿using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Web.Mail;
using SpringWaterDataAccess;
using System.Text;
using System.Configuration;

namespace sow
{
	/// <summary>
	/// Summary description for wangji.
	/// </summary>
	public partial class wangji : System.Web.UI.Page
	{
		protected System.Web.UI.WebControls.ValidationSummary valSum;
	
		protected void Page_Load(object sender, System.EventArgs e)
		{
			// Put user code to initialize the page here
		}

		#region Web Form Designer generated code
		override protected void OnInit(EventArgs e)
		{
			//
			// CODEGEN: This call is required by the ASP.NET Web Form Designer.
			//
			InitializeComponent();
			base.OnInit(e);
		}
		
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{    

		}
		#endregion

        protected void Button1_Click(object sender, System.EventArgs e)
        {
           
            string password = UserObject.GetPassword(idEmail.Value);
            StringBuilder body = new StringBuilder();
            body.Append("Your password is ");
            body.Append(password);
            body.Append("\n\n");
            body.Append("Thank you and God bless\n");
            body.Append("http://www.springofwater.net");
            
            MailMessage mailmessage = new MailMessage();
            //SmtpMail.SmtpServer = "smtpout.secureserver.net";
            //SmtpMail.SmtpServer = "smtp.gmail.com";

            mailmessage.From = "contact@quanyuan.info";
            mailmessage.To = idEmail.Value;
            //mailmessage.To = "kanqiu@hotmail.com;kanqmail@gmail.com";
            mailmessage.Subject = "Your password for springofwater.net";
            mailmessage.Body = body.ToString();
            mailmessage.Headers.Add("Reply-To", mailmessage.From);
            mailmessage.BodyFormat = MailFormat.Html;

            mailmessage.Fields["http://schemas.microsoft.com/cdo/configuration/smtpaccountname"] = mailmessage.From;	
            mailmessage.Fields["http://schemas.microsoft.com/cdo/configuration/sendusername"] = mailmessage.From;		
            mailmessage.Fields["http://schemas.microsoft.com/cdo/configuration/sendpassword"] = "springofwater";
            mailmessage.Fields["http://schemas.microsoft.com/cdo/configuration/smtpauthenticate"] = 1;			//验证级别0,1,2
            mailmessage.Fields["http://schemas.microsoft.com/cdo/configuration/languagecode"] = 0x0804;			//语言代码
            mailmessage.Fields["http://schemas.microsoft.com/cdo/configuration/smtpserver"] = "smtpout.secureserver.net";
            mailmessage.Fields["http://schemas.microsoft.com/cdo/configuration/smtpserverport"] = 80;
            mailmessage.Fields["http://schemas.microsoft.com/cdo/configuration/languagecode"] = 0x0804; 
            mailmessage.Fields["http://schemas.microsoft.com/cdo/configuration/smtpusessl"]= "true";

            mailmessage.BodyFormat = MailFormat.Html;
            mailmessage.BodyEncoding = System.Text.Encoding.GetEncoding("GB2312");

            try
            {
                SmtpMail.Send(mailmessage);
            }catch (Exception ex)
            {
                Response.Write("Send failure: " + ex.ToString());
            }
            Response.Redirect("index.aspx");
        }
	}
}
